/**   
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-07 14:44:46  
 * Copyright (c) 2015- joysuch-版权所有     
 */

package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpMainMaterial;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

/**
 * BpMainMaterialDao
 * 
 */
public interface BpMainMaterialDao
        extends JpaRepository<BpMainMaterial, Long>, QuerydslPredicateExecutor<BpMainMaterial> {
    public Page<BpMainMaterial> findAll(Specification<BpMainMaterial> spec, Pageable pageable);

    public BpMainMaterial save(BpMainMaterial bean);

    public void delete(BpMainMaterial bean);

    @Query("select count(m) from BpMainMaterial m where type=?1 and code=?2")
    Long countOfTypeAndCode(String type, String code);

    @Query("select count(m) from BpMainMaterial m where type=?1 and code=?2 and id != ?3")
    Long countOfTypeAndCode(String type, String code, Long excludeId);
}
